<template>
  <div class="article-page">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>面经后台</el-breadcrumb-item>
      <el-breadcrumb-item>面经管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card shadow="never" border="false">
      <template #header>
        <div class="header">
          <span>共 300 条记录</span>
          <el-button
            icon="el-icon-plus"
            size="small"
            type="primary"
            round>
            添加面经
          </el-button>
        </div>
      </template>
      <!--
        el-table 属性
          data: 表格数据, 必须是一个数组
        el-table-column
          width: 宽度
          label: 表头的文字
          prop: 字符串类型, 要在此列渲染的数据属性名
       -->
      <el-table
      :data="list"
      style="width: 100%">
      <el-table-column
        prop="stem"
        label="标题"
        width="350">
      </el-table-column>
      <el-table-column
        prop="creator"
        label="作者"
        width="130">
      </el-table-column>
      <el-table-column
        prop="likeCount"
        label="点赞"
        width="130">
      </el-table-column>
      <el-table-column
        prop="views"
        label="浏览数"
        width="130">
      </el-table-column>
      <el-table-column
        prop="createdAt"
        label="更新时间"
        width="200">
      </el-table-column>
      <el-table-column
        label="操作">
        <!-- 作用域插槽: 获取组件内部的数据在父组件中显示或者操作 -->
        <template #default={row}>
          <div class="actions">
            <i class="el-icon-view"></i>
            <i class="el-icon-edit-outline"></i>
            <i class="el-icon-delete" @click="del(row.id)"></i>
          </div>
        </template>
      </el-table-column>
      </el-table>

    </el-card>

    <!-- 放抽屉组件 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="q.current"
      :page-sizes="[10, 15, 20, 30]"
      :page-size="q.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
// axios 接口
import { getArticles } from '@/api/article'

// require styles
// import 'quill/dist/quill.core.css'
// import 'quill/dist/quill.snow.css'
// import 'quill/dist/quill.bubble.css'
// import { quillEditor } from 'vue-quill-editor'
export default {
  name: 'article-page',
  data () {
    return {
      // 收集表单的数据对象

      // 验证规则对象

      q: {
        current: 1,
        pageSize: 10
      },
      total: 0,
      list: []
      // 保存的时候组件操作的类型 添加 || 预览 || 修改
    }
  },
  computed: {

  },
  async created () {
    this.loadArticle()
  },
  methods: {
    // 获取列表的数据进行渲染
    async loadArticle () {
      const res = await getArticles()
      console.log(res)
      this.list = res.data.rows
      this.total = res.data.total
    },
    // 分页
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
      this.q.pageSize = val
      this.loadArticle()
    },
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`)
      this.q.current = val
      this.loadArticle()
    },

    // 删除
    del (id) {
      console.log(id)
    }
  }
  // components: {
  //   quillEditor
  // }
}
</script>

<style lang="scss" scoped>
.el-card {
  margin-top: 25px;
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 16px;
  }
  .actions {
    font-size: 18px;
    display: flex;
    justify-content: space-around;
    color: #666;
    > i:hover {
      color: rgba(114, 124, 245, 1);
      cursor: pointer;
    }
  }
}
.el-pagination {
  margin-top: 20px;
  text-align: center;
}
.el-breadcrumb {
  margin-top: 10px;
}
.el-form {
  padding-right: 40px;
}
.quill-editor {
  ::v-deep .ql-editor {
    height: 300px;
  }
}
.el-rate {
  padding: 10px 0;
}
.article-preview {
  padding: 0 40px 40px 40px;
  > h5 {
    font-size: 20px;
    color: #666;
    border-bottom: 1px dashed #ccc;
    padding-bottom: 30px;
    margin: 0 0 20px 0;
  }
}
</style>
